#pragma once

#include <qstring.h>
#include "FeatureShape/Feature.h"
#include <QList>

class QShapeVersion;

// 一个表达式 = 公式 + 特征值s
// 公式代表修改特征值的方式
// 特征值是体素的特征（宽、高、半径）或操作的特征（倒角的半径）

class Expression
{
	friend class ExpressionManager;

public:
	Expression(bool bIsNativeExpression);
	Expression(QString expression, QString value, std::shared_ptr<Feature> targetFeature, bool bIsNativeExpression = true);

	QString GetExpression() const
	{
        return m_expression;
	}

    QString GetValue() const
    {
        return m_value;
    }

    QString GetTargetFeatureKey() const
    {
		if (!m_targetFeature)
		{
            return QString("");
		}
        return m_targetFeature->GetKey();
    }

	QString GetTargetFeatureContent() const
	{
        if (!m_targetFeature)
		{
			return QString("");
		}
		return m_targetFeature->m_content;
	}

	bool IsNativeExpression() const
	{
		return m_bIsNativeExpression;
	}
	void SetKey(const std::shared_ptr<Feature>& targetFeature)
	{
		m_targetFeature = targetFeature;
	}
	void SetExpression(const QString& expression, const QList<std::shared_ptr<Feature>>& featureList, float newValue);

	bool operator==(const Expression& other) const
	{
		return m_expressionID == other.m_expressionID;
	}

private:
	// 表达式（公式）
	QString m_expression;
	// 表达式值（计算结果值）
    QString m_value;

	// 表达式的计算值将用于修改此特征值
	std::shared_ptr<Feature> m_targetFeature;

	// 参与运算的特征值
	QList<std::shared_ptr<Feature>> m_featureList;

	// 是否为原生表达式
	bool m_bIsNativeExpression;

	// expression的ID
	int m_expressionID;

	static int expressionCount;
};

